package nexus.com.container
{
	import flash.display.DisplayObject;
	import flash.display.Graphics;
	
	import nexus.base.NXSprite;
	
	public class Container extends NXSprite
	{
		//-----------------------------------------------------------------------------------
		//
		// private vars
		//
		//-----------------------------------------------------------------------------------
		
		private var _wrapperContainer : WrapperContainer;
		private var _maskClip : NXSprite;
		//-----------------------------------------------------------------------------------
		//
		// protected vars
		//
		//-----------------------------------------------------------------------------------
		
		
		private var _maskPaddingTop : Number = 0;
		private var _maskPaddingRight : Number = 0;
		private var _maskPaddingBottom : Number = 0;
		private var _maskPaddingLeft : Number = 0;
		
		//-----------------------------------------------------------------------------------
		//
		// public vars
		//
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// constructor
		//
		//-----------------------------------------------------------------------------------
		
		public function Container()
		{
			super();
			
			
			_wrapperContainer = new WrapperContainer();
			addChild( _wrapperContainer );
			
			_wrapperContainer.x = paddingLeft-maskPaddingLeft;
			_wrapperContainer.y = paddingTop-maskPaddingTop;
			
			_maskClip = new NXSprite();
			addChild( _maskClip );
			var g : Graphics = _maskClip.graphics;
			g.beginFill( 0x000000, 1 );
			g.drawRect( 0,0,1,1 );
			g.endFill();
			
			_maskClip.width = viewWidth-paddingLeft-paddingRight-maskPaddingLeft -maskPaddingRight;
			_maskClip.height = viewHeight-paddingTop-paddingBottom-maskPaddingTop-maskPaddingBottom;
			_wrapperContainer.mask = _maskClip;
			
		}
		
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// setter / getter
		//
		//-----------------------------------------------------------------------------------

		public function get maskPaddingLeft():Number
		{
			return _maskPaddingLeft;
		}

		public function set maskPaddingLeft(value:Number):void
		{
			_maskPaddingLeft = value;
			
		}

		public function get maskPaddingBottom():Number
		{
			return _maskPaddingBottom;
		}

		public function set maskPaddingBottom(value:Number):void
		{
			_maskPaddingBottom = value;
			
		}

		public function get maskPaddingRight():Number
		{
			return _maskPaddingRight;
		}

		public function set maskPaddingRight(value:Number):void
		{
			_maskPaddingRight = value;
			
		}

		public function get maskPaddingTop():Number
		{
			return _maskPaddingTop;
		}

		public function set maskPaddingTop(value:Number):void
		{
			_maskPaddingTop = value;
			
		}

		public function get maskClip():NXSprite
		{
			return _maskClip;
		}

		public function set wrapContainerHeight(value:Number):void
		{
			this._wrapperContainer.viewHeight = value;
		}

		public function get wrapperContainer():WrapperContainer
		{
			return _wrapperContainer;
		}
		
		public function get numElemnt():int
		{
			return _wrapperContainer.numChildren;
		}
		
		//-----------------------------------------------------------------------------------
		//
		// public function
		//
		//-----------------------------------------------------------------------------------
		

		override public function updateDisplayList():void
		{
			super.updateDisplayList();
			
			_maskClip.width = viewWidth-paddingLeft-paddingRight-maskPaddingLeft -maskPaddingRight;
			_maskClip.height = viewHeight-paddingTop-paddingBottom-maskPaddingTop-maskPaddingBottom;
		}
		
		
		
		
		
		
		
		
		public function addElement( item : DisplayObject ):void
		{
			_wrapperContainer.addChild( item );
		}
		
		public function addElementAt( item : DisplayObject, idx : int ):void
		{
			_wrapperContainer.addChildAt( item, idx );
		}
		
		public function removeElement( item : DisplayObject ):void
		{
			_wrapperContainer.removeChild( item );
		}
		
		public function removeElementAt( item : DisplayObject, idx : int ):void
		{
			_wrapperContainer.removeChildAt( idx );
		}
		
		
		public function removeAllElement():void
		{
			var len:int = _wrapperContainer.numChildren;
			for (var i:int = 0; i < len; i++) 
			{
				_wrapperContainer.removeChild( _wrapperContainer.getChildAt( 0 ) );
			}
		}
		
		public function setElementIndex( item : DisplayObject, idx : int ):void
		{
			_wrapperContainer.setChildIndex( item, idx );
		}
		
		public function getElementIndex( item : DisplayObject ):int
		{
			return _wrapperContainer.getChildIndex( item );
		}
		
		//-----------------------------------------------------------------------------------
		//
		// protected function
		//
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// private function
		//
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// event handler
		//
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// destory
		//
		//-----------------------------------------------------------------------------------
		override public function destory():void
		{
			super.destory();
		}
	}
	
}